package com.kaishengit.servlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.kaishengit.entity.Message;



public class context extends HttpServlet {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	

	public void init() throws ServletException {
	
	}
	
	@SuppressWarnings("unchecked")
	protected void service(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String context=request.getParameter("context");
		
		ServletContext application=getServletContext();
		List<Message> con=(List<Message>)application.getAttribute("neirong") ;
		if(con==null){
			con=new ArrayList<Message>();
			
		}

		Message msg=new Message();
		msg.setContext(context);
		msg.setUsername((String)request.getSession().getAttribute("key"));
		msg.setTime(DateUtil.getNow());
		con.add(msg);
		
		//ServletContext s=getServletContext();
		application.setAttribute("neirong", con);
		response.sendRedirect("left-right.jsp");
		
	}

	public void destroy() {

	}
	
}
